import logging

import requests

ses = requests.session()

from config import URL


class RechargeApi:

    def __init__(self, ses):
        # 接收session对象的变量
        self.ses = ses

    # 获取充值验证码接口
    def get_recharge_verify_code(self, r):
        url = URL + "/common/public/verifycode/" + f"{r}"
        resp = self.ses.get(url)
        print(f"获取充值验证码返回的状态码{resp.status_code}")
        logging.info(f"获取充值验证码返回的状态码{resp.status_code}")
        return resp

    # 充值接口
    def recharge(self,form_data):
        # 定义一个字典变量，用来接收请求体数据
        self.ses.get(URL + "/common/public/verifycode/123")
        form_dict = {"keywords": "18376789000", "password": "L513149270"}
        self.ses.post(url=URL + "/member/public/login", data=form_dict)
        url = URL + "/trust/trust/recharge"
        resp = self.ses.post(url, form_data)
        return resp

    # 第三方充值接口
    def third_recharge(self,url,form_dict):
        resp = self.ses.post(url=url, data=form_dict)
        logging.info(f"第三方充值接口的响应体数据{resp.text}")
        return resp
